package com.example.huadi1.service.Imp;

import com.example.huadi1.dto.Registration;
import com.example.huadi1.mapper.RegistrationMapper;
import com.example.huadi1.service.RegistrationService;
import com.example.huadi1.utils.AjaxResult;
import com.example.huadi1.utils.PageUtils;
import com.example.huadi1.utils.msg.RegistrationJson;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class RegistrationServiceImpl implements RegistrationService {

    @Autowired
    private RegistrationMapper registrationMapper;
    //分页取得所有的数据
    @Override
    public AjaxResult allRegis(RegistrationJson registrationJson){
        PageHelper.startPage(registrationJson.getPageNum(),registrationJson.getPageSize());
        List<Registration> registrationList = registrationMapper.allRegis();
        PageInfo<Registration> of = PageInfo.of(registrationList);
        PageUtils pageUtils = new PageUtils(of);
        return AjaxResult.success(pageUtils);
    }
    //添加数据，返回成功数据
    @Override
    public AjaxResult addRegis(Registration registration) {
        registrationMapper.addRegis(registration);
        return AjaxResult.success();
    }
    //线下更新数据，返回成功数据
    @Override
    public AjaxResult updateOffline(Registration registration){
        registrationMapper.updateOffline(registration);
        registrationMapper.updateRegisteration();
        return AjaxResult.success();
    }
    //线上
    @Override
    public AjaxResult updateOnline(Registration registration){
        registrationMapper.updateOnline(registration);
        registrationMapper.updateRegisteration();
        return  AjaxResult.success();
    }
    //绿色通道
    @Override
    public AjaxResult GreenChannel(Integer stu_ID){
        registrationMapper.GreenChannel(stu_ID);
        return AjaxResult.success();
    }
    //通过id取得数据
    @Override
    public Registration findById(Integer stu_ID){return registrationMapper.findById(stu_ID);}
    //通过页号和页面大小返回对象队列,测试
    @Override
    public List<Registration> findByPage(Map<String, Object> map){
        return registrationMapper.findByPage(map);
    }
    //绿色通道报表
    @Override
    public AjaxResult greenChannelForm(RegistrationJson registrationJson){
        PageHelper.startPage(registrationJson.getPageNum(),registrationJson.getPageSize());
        List<Registration> registrationList = registrationMapper.greenChannelForm();
        for (int r = 0; r < registrationList.size(); r++) {
            Registration a = registrationList.get(r);
            a.setResult("申请");
        }
        PageInfo<Registration> of = PageInfo.of(registrationList);
        PageUtils pageUtils = new PageUtils(of);
        return AjaxResult.success(pageUtils);
    }
    //现场缴费报表
    @Override
    public AjaxResult offlineForm(RegistrationJson registrationJson){
        PageHelper.startPage(registrationJson.getPageNum(),registrationJson.getPageSize());
        List<Registration> registrationList = registrationMapper.registrationForm();
        for (int r = 0; r < registrationList.size(); r++) {
            Registration a = registrationList.get(r);
            if(a.getTution_method()==1){
                a.setResult("现场缴费");
            }
            else if(a.getTution_method()==2){
                a.setResult("非现场缴费");
            }
            else {
                a.setResult("未缴费");
            }
            if(a.getAgency_fee_method()==1){
                a.setResult1("现场缴费");
            }
            else if(a.getAgency_fee_method()==2){
                a.setResult1("非现场缴费");
            }
            else {
                a.setResult1("未缴费");
            }
            if(a.getHotel_expense_method()==1){
                a.setResult2("现场缴费");
            }
            else if(a.getHotel_expense_method()==2){
                a.setResult2("非现场缴费");
            }
            else {
                a.setResult2("未缴费");
            }
        }
        PageInfo<Registration> of = PageInfo.of(registrationList);
        PageUtils pageUtils = new PageUtils(of);
        return AjaxResult.success(pageUtils);
    }
    //网上缴费报表
    @Override
    public AjaxResult onlineForm(RegistrationJson registrationJson){
        PageHelper.startPage(registrationJson.getPageNum(),registrationJson.getPageSize());
        List<Registration> registrationList = registrationMapper.registrationForm();
        for (int r = 0; r < registrationList.size(); r++) {
            Registration a = registrationList.get(r);
            if(a.getTution_method()==1){
                a.setResult("非网上缴费");
            }
            else if(a.getTution_method()==2){
                a.setResult("网上缴费");
            }
            else {
                a.setResult("未缴费");
            }
            if(a.getAgency_fee_method()==1){
                a.setResult1("非网上缴费");
            }
            else if(a.getAgency_fee_method()==2){
                a.setResult1("网上缴费");
            }
            else {
                a.setResult1("未缴费");
            }
            if(a.getHotel_expense_method()==1){
                a.setResult2("非网上缴费");
            }
            else if(a.getHotel_expense_method()==2){
                a.setResult2("网上缴费");
            }
            else {
                a.setResult2("未缴费");
            }
        }
        PageInfo<Registration> of = PageInfo.of(registrationList);
        PageUtils pageUtils = new PageUtils(of);
        return AjaxResult.success(pageUtils);
    }
    //综合报表
    @Override
    public AjaxResult sumForm(RegistrationJson registrationJson){
        PageHelper.startPage(registrationJson.getPageNum(),registrationJson.getPageSize());
        List<Registration> registrationList = registrationMapper.registrationForm();
        for (int r = 0; r < registrationList.size(); r++) {
            Registration a = registrationList.get(r);
            if(a.getTution_method()==1){
                a.setResult("现场缴费");
            }
            else if(a.getTution_method()==2){
                a.setResult("网上缴费");
            }
            else {
                a.setResult("未缴费");
            }
            if(a.getAgency_fee_method()==1){
                a.setResult1("现场缴费");
            }
            else if(a.getAgency_fee_method()==2){
                a.setResult1("网上缴费");
            }
            else {
                a.setResult1("未缴费");
            }
            if(a.getHotel_expense_method()==1){
                a.setResult2("现场缴费");
            }
            else if(a.getHotel_expense_method()==2){
                a.setResult2("网上缴费");
            }
            else {
                a.setResult2("未缴费");
            }
        }
        PageInfo<Registration> of = PageInfo.of(registrationList);
        PageUtils pageUtils = new PageUtils(of);
        return AjaxResult.success(pageUtils);
    }
    //报到报表
    @Override
    public AjaxResult registrationForm(RegistrationJson registrationJson){
        PageHelper.startPage(registrationJson.getPageNum(),registrationJson.getPageSize());
        List<Registration> registrationList = registrationMapper.registrationForm();
        for (int r = 0; r < registrationList.size(); r++) {
                Registration a = registrationList.get(r);
                if(a.getRegisteration()==1){
                   a.setResult("已报到");
                }
                else {
                    a.setResult("未报到");
                }
        }
        PageInfo<Registration> of = PageInfo.of(registrationList);
        PageUtils pageUtils = new PageUtils(of);
        return AjaxResult.success(pageUtils);
    }
}
